package com.app.common.activity;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.view.WindowManager;

import com.app.common.util.SystemBarManager;
import com.readystatesoftware.systembartint.SystemBarTintManager;

/**
 * Created by zhoulikai on 17/2/16.
 * 通用接口设置，所有项目的基类
 */

public abstract class BaseActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initAppConfigure();
        setContentView(initLayoutId());
        initAppSystemBar();
        initPage();
    }

    /**
     * 初始化全局属性
     */
    public abstract void initAppConfigure();

    /**
     * 初始化状态颜色
     *
     * @return
     */
    public abstract int getAppSystemBarColor();

    /**
     * 是否开启状态栏颜色设置功能
     *
     * @return
     */
    public abstract boolean isOpenTranslucentStatus();

    /**
     * 初始化layoutId
     *
     * @return
     */
    public abstract int initLayoutId();

    /**
     * 初始化界面数据
     */
    public abstract void initPage();

    private void initAppSystemBar() {
        if (isOpenTranslucentStatus()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                setTranslucentStatus(true);
            }

            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(getAppSystemBarColor());//通知栏所需颜色
//            tintManager.setStatusBarTintColor(0x00ffffff);
        }


    }


    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }


    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
